package com.chixing.controller;

import com.chixing.service.StoreService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StoreController {
    @Autowired
    private StoreService storeService;

    @GetMapping("stores/{storeAddressArea}")
    @ResponseBody
    public ServerResponse getByStoreAddressArea(@PathVariable("storeAddressArea") String storeAddressArea){
        System.out.println("1111111111");
        return storeService.getByStoreAddressArea(storeAddressArea);
    }

    @GetMapping("store")
    @ResponseBody
    public ServerResponse getByConditions(@RequestParam("storeName") String storeName,
                                          @RequestParam("storeTelno") Long storeTelno,
                                          @RequestParam("storeAddressArea") String storeAddressArea,
                                          @RequestParam("storeAddress") String storeAddress,
                                          @RequestParam("storeDescribe") String storeDescribe) {
        return storeService.getByConditions(storeName, storeTelno, storeAddressArea, storeAddress, storeDescribe);
    }

    @GetMapping("store/{city}")
    @ResponseBody
    public ServerResponse getStoreByCity(@PathVariable("city")String city){
//        System.out.println("city:" + city);
        ServerResponse serverResponse = storeService.getStoreByCity(city);
        System.out.println(serverResponse.getData());
        return serverResponse;
    }

}